package com.qzy.sort;


import com.qzy.entity.Student;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

/**
 * @描述
 * @创建人 joy_qiu
 * @创建时间 2019-12-23-15:24
 * @修改人和其它信息
 */
public class ListSort {
    public static void main(String[] args) {
        Student stu1 = new Student("a",12);
        Student stu2 = new Student("b",11);
        Student stu3 = new Student("c",13);
        Student stu4 = new Student("d",18);
        Student stu5 = new Student("e",110);
        List<Student> list = new ArrayList<>();
        list.add(stu1);
        list.add(stu2);
        list.add(stu3);
        list.add(stu4);
        list.add(stu5);
        System.out.println("根据学生的年龄排序");
        list.sort(Comparator.comparing(Student::getAge));
        list.forEach(System.out::println);
        System.out.println("根据学生的年龄排序翻转排序");
        list.sort(Comparator.comparing(Student::getAge).reversed());
        list.forEach(System.out::println);
    }
}
